package cn.ipanel.bigdata.utils

import org.apache.spark.Partitioner

/**
 * @author lzz
 * @projectName iBigdata
 * @date 2022/7/13 17:58
 * @description: 工具，用于将一个用户的上报，放在一个executor处理
 */
class UserPartitioner(partition: Int) extends Partitioner {
  override def numPartitions: Int = partition

  override def getPartition(key: Any): Int = key match {
    case null => 0
    case _ => {
      val partId = key.hashCode() % partition
      partId + (if (partId < 0) partition else 0)
    }
  }

  override def equals(other: Any): Boolean = other match {
    case h: UserPartitioner =>
      h.numPartitions == numPartitions    case _ =>

      false
  }
}
